package com.example.tao_city.text1;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by TAO_CITY on 2018/1/22.
 */

public class nfcchongzhizhong extends Activity implements View.OnClickListener{
    private ImageView back,jin;
    private TextView rnb,tip,tishi;
    private ImageView jindu1,jindu2,jindu3,jindu4,jindu5,jindu6,jindu7,jindu8,jindu9;
    private RelativeLayout heimu;
    private int a=0;
    private boolean stop=true;
    private boolean time=true;
    private Handler handler;
    private Intent in;
    private String kahao,yue,chongqian;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.nfcchongzhizhong);
        initview();
        getin();
        handler=new Handler();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        finish();
    }

    private void initview() {
        rnb=findViewById(R.id.nfcchongzhizhong_qian);
        back=findViewById(R.id.nfcchongzhizhong_back);
        jindu1=findViewById(R.id.nfcchongzhizhong_jindu1);
        jindu2=findViewById(R.id.nfcchongzhizhong_jindu2);
        jindu3=findViewById(R.id.nfcchongzhizhong_jindu3);
        jindu4=findViewById(R.id.nfcchongzhizhong_jindu4);
        jindu5=findViewById(R.id.nfcchongzhizhong_jindu5);
        jindu6=findViewById(R.id.nfcchongzhizhong_jindu6);
        jindu7=findViewById(R.id.nfcchongzhizhong_jindu7);
        jindu8=findViewById(R.id.nfcchongzhizhong_jindu8);
        jindu9=findViewById(R.id.nfcchongzhizhong_jindu9);
        heimu=findViewById(R.id.nfcchongzhizhong_heiping);
        tip=findViewById(R.id.nfcchongzhizhong_tip);
        jin=findViewById(R.id.nfcchongzhizhong_jin);
        tishi=findViewById(R.id.nfcchongzhizhong_tishi);


        tishi.setOnClickListener(this);
        jin.setOnClickListener(this);
        back.setOnClickListener(this);
        rnb.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.nfcchongzhizhong_back:
                finish();
                break;
            case R.id.nfcchongzhizhong_qian:
                if(time) {
                    tip.setVisibility(View.VISIBLE);
                    heimu.setVisibility(View.VISIBLE);
                    back.setEnabled(false);
                    stop=true;
                    runnable.run();
                    time=false;
                }else {
                    tip.setVisibility(View.INVISIBLE);
                    heimu.setVisibility(View.INVISIBLE);
                    setan();
                    back.setEnabled(true);
                    stop=false;
                    a=0;
                    time=true;
                }
                break;
            case R.id.nfcchongzhizhong_tishi:
               Intent ino=new Intent();
               ino.putExtra("kahao",kahao);
               ino.putExtra("yue",yue);
               ino.putExtra("chongqian",chongqian);
               ino.setClass(nfcchongzhizhong.this,Nfcchenggong.class);
               //Toast.makeText(this,kahao+";"+yue+";"+chongqian,Toast.LENGTH_SHORT).show();
               startActivity(ino);
               break;

        }

    }

    public void getin() {
        in=getIntent();
        String qian=in.getStringExtra("qian");
        kahao=in.getStringExtra("kahao");
        yue=in.getStringExtra("yue");
        chongqian= in.getStringExtra("qian");
        rnb.setText("+"+qian);
    }
    Runnable runnable=new Runnable() {
        @Override
        public void run() {
            if(stop){
                setan();
                setlian(a);
                a++;
                if(a==10){
                    a=0;
                }
                handler.postDelayed(this,500);
            }
        }
    };
    private void setan(){
        jindu1.setVisibility(View.INVISIBLE);
        jindu2.setVisibility(View.INVISIBLE);
        jindu3.setVisibility(View.INVISIBLE);
        jindu4.setVisibility(View.INVISIBLE);
        jindu5.setVisibility(View.INVISIBLE);
        jindu6.setVisibility(View.INVISIBLE);
        jindu7.setVisibility(View.INVISIBLE);
        jindu8.setVisibility(View.INVISIBLE);
        jindu9.setVisibility(View.INVISIBLE);
    }
    private void setlian(int i){
        switch (i){
            case 1:
                jindu1.setVisibility(View.VISIBLE);
                break;
            case 2:
                jindu1.setVisibility(View.VISIBLE);
                jindu2.setVisibility(View.VISIBLE);
                break;
            case 3:
                jindu1.setVisibility(View.VISIBLE);
                jindu2.setVisibility(View.VISIBLE);
                jindu3.setVisibility(View.VISIBLE);
                break;
            case 4:
                jindu1.setVisibility(View.VISIBLE);
                jindu2.setVisibility(View.VISIBLE);
                jindu3.setVisibility(View.VISIBLE);
                jindu4.setVisibility(View.VISIBLE);
                break;
            case 5:
                jindu1.setVisibility(View.VISIBLE);
                jindu2.setVisibility(View.VISIBLE);
                jindu3.setVisibility(View.VISIBLE);
                jindu4.setVisibility(View.VISIBLE);
                jindu5.setVisibility(View.VISIBLE);
                break;
            case 6:
                jindu1.setVisibility(View.VISIBLE);
                jindu2.setVisibility(View.VISIBLE);
                jindu3.setVisibility(View.VISIBLE);
                jindu4.setVisibility(View.VISIBLE);
                jindu5.setVisibility(View.VISIBLE);
                jindu6.setVisibility(View.VISIBLE);
                break;
            case 7:
                jindu1.setVisibility(View.VISIBLE);
                jindu2.setVisibility(View.VISIBLE);
                jindu3.setVisibility(View.VISIBLE);
                jindu4.setVisibility(View.VISIBLE);
                jindu5.setVisibility(View.VISIBLE);
                jindu6.setVisibility(View.VISIBLE);
                jindu7.setVisibility(View.VISIBLE);
                break;
            case 8:
                jindu1.setVisibility(View.VISIBLE);
                jindu2.setVisibility(View.VISIBLE);
                jindu3.setVisibility(View.VISIBLE);
                jindu4.setVisibility(View.VISIBLE);
                jindu5.setVisibility(View.VISIBLE);
                jindu6.setVisibility(View.VISIBLE);
                jindu7.setVisibility(View.VISIBLE);
                jindu8.setVisibility(View.VISIBLE);
                break;
            case 9:
                jindu1.setVisibility(View.VISIBLE);
                jindu2.setVisibility(View.VISIBLE);
                jindu3.setVisibility(View.VISIBLE);
                jindu4.setVisibility(View.VISIBLE);
                jindu5.setVisibility(View.VISIBLE);
                jindu6.setVisibility(View.VISIBLE);
                jindu7.setVisibility(View.VISIBLE);
                jindu8.setVisibility(View.VISIBLE);
                jindu9.setVisibility(View.VISIBLE);
                break;
        }
    }
}
